package joshua.hibernate.mapping;
import java.util.Date;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.AnnotationConfiguration;

@Entity
@Table(name="UserThread")
public class UserThreadEntity {

	
	public UserThreadEntity() {}
	
	
	@Id
	@GeneratedValue
	public Integer getThreadId(){
		return threadId;
	}
	
	
	public void setThreadId(int threadId) {
		this.threadId = threadId;
	}
	
	
	public String getUserName(){
		return userName;
	}
	
	
	public void setUserName(String userName) {
		this.userName = userName;
	}
	
	
	public Date getUpdateDate() {
		return updateDate;
	}
	
	
	public void setUpdateDate(Date updateDate) {
		this.updateDate = updateDate;
	}
	
	
	public String getDetail(){
		return detail;
	}
	
	
	public void setDetail(String detail) {
		this.detail = detail;
	}
	
	
	
	public static void main(String[] args) {
		SessionFactory sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
		Session session = sessionFactory.openSession();
		Transaction tx = null;
		try {
			tx = session.beginTransaction();
			List res = session.createQuery("FROM UserThreadEntity").list();
			tx.commit();
			tx = null;
			System.out.println(res);
		} catch (HibernateException e) {
			if (tx != null) {
				tx.rollback();
			}
			e.printStackTrace();
		} finally {
			session.close();
		}
	}
	private int threadId ;
	private String userName;
	private String detail;
	private Date updateDate;
}
